<!doctype html>
<html>
  <head>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-132775238-1"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-132775238-1');
    </script>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
    <link href="https://fonts.googleapis.com/css?family=Varela+Round" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;600&family=Roboto+Mono&display=swap" rel="stylesheet">
    <style>
      .btn{
        width: 70px;
        height: 70px;
        background-color: #47AFE8;
        color: #fff;
        font-size: 12px;
        display: block;
        border: none;
        margin: 2px;
        border-radius: 2px;
        cursor:pointer;
        outline:none;
      }
      rapi-doc{
        width:100%;
      }
    </style>
    <script type="module" src="../rapidoc-min.js"></script>
    <script>
      function getRapiDoc(){
        return document.getElementById("thedoc");
      }  
      function changeAttr(attr){
        let arr=[];
        let rand = Math.floor(Math.random() * 10);

        if (attr==="heading-text"){
          arr = ['SPIDER-MAN', "IRON-MAN", "You Tube", "BLACK-PANTHER", "RapiDoc", "SUPER-MAN", "BAT-MAN", "JOKER", "WONDER-WOMAN", "SUPER-GIRL", "CAT-WOMAN", "LARA-CROFT"];
        }
        else if (attr==="header-color"){
          arr = ['#2d87e2', "#ff6961", "#34A853", "#FBBC05", "#66757F", "#FFFFFF", "#3B5998", "#8B9DC3", "#7CBB00", "#7B0099", " #FF9900"];
          if (arr[rand] !== '#FFFFFF'){
            getRapiDoc().setAttribute('primary-color', arr[rand] );
          }
          else{
            getRapiDoc().setAttribute('primary-color', '#FF3D00' );
          }
        }
        else if(attr==="spec-url"){
          arr = [
             "https://petstore.swagger.io/v2/swagger.json" 
            ,"https://api.apis.guru/v2/specs/apideck.com/crm/0.0.1/openapi.yaml"
            ,"https://api.apis.guru/v2/specs/atlassian.com/jira/1001.0.0-SNAPSHOT/openapi.yaml",
            ,"https://api.apis.guru/v2/specs/googleapis.com/managedidentities/v1beta1/openapi.yaml"
            ,"https://api.apis.guru/v2/specs/azure.com/azureactivedirectory/2017-04-01/swagger.yaml"
            ,"https://api.apis.guru/v2/specs/gitlab.com/v3/swagger.yaml"
            ,"https://api.apis.guru/v2/specs/quotes.rest/3.1/openapi.yaml"
            ,"https://api.apis.guru/v2/specs/azure.com/workloadmonitor-Microsoft.WorkloadMonitor/2018-08-31-preview/swagger.json"
            ,"https://api.apis.guru/v2/specs/api2cart.com/1.1/openapi.yaml"
            ,"https://api.apis.guru/v2/specs/chompthis.com/1.0.0-oas3/openapi.yaml"
          ];
        }
        else{
          return;
        }

        if (arr[rand]){
          getRapiDoc().setAttribute(attr, arr[rand] );
        }
        else{
          getRapiDoc().setAttribute(attr, arr[0] );
        }
      }
    
      function changeLayout(){
        let currLayout = getRapiDoc().getAttribute('layout');
        let newLayout = currLayout==="row"?"column":"row";
        getRapiDoc().setAttribute('layout', newLayout );
      }

      function changeRenderStyle() {
        let currRender = getRapiDoc().getAttribute('render-style');
        let newRender = currRender === "read" ? "view" : "read";
        getRapiDoc().setAttribute('render-style', newRender );
      }

      function toggleAttr(attr){
        if (getRapiDoc().getAttribute(attr) === 'false'){
          getRapiDoc().setAttribute(attr,"true");
        }
        else{
          getRapiDoc().setAttribute(attr,"false");
        }
      }
    
      function toggleTheme(){
        if (getRapiDoc().getAttribute('theme') === 'dark'){
          getRapiDoc().setAttribute('theme',"light");
        }
        else{
          getRapiDoc().setAttribute('theme',"dark");
        }
      }

      function changeFont(){
        if (getRapiDoc().getAttribute('regular-font') === "'Varela Round'"){
          getRapiDoc().setAttribute('regular-font',"'Open Sans'");
        }
        else{
          getRapiDoc().setAttribute('regular-font',"'Varela Round'");
        }
      }
    
      function changeLogo(){
        var logoEl = document.getElementById("logo");
        if (logoEl){
          logoEl.parentNode.removeChild(logoEl);
        }
        else{
          let newLogoEl = document.createElement("img");
          newLogoEl.setAttribute('id', "logo");
          newLogoEl.setAttribute('slot', "logo");
          newLogoEl.setAttribute('src', "");
          getRapiDoc().appendChild(newLogoEl);
          getRapiDoc().setAttribute('primary-color', "#FF3D00" );
          
        }
      }
    </script>
  </head>
  <body>
    <rapi-doc id="thedoc" spec-url="https://petstore.swagger.io/v2/swagger.json" mono-font = "Roboto Mono"> 
      <div style="display:flex; margin:10px; justify-content:center;flex-wrap: wrap;">
        <button class="btn" onclick="changeAttr('header-color')">Change Header Color</button>
        <button class="btn" onclick="changeRenderStyle()">Render Style</button>
        <button class="btn" onclick="changeAttr('heading-text')">Change Heading Text</button>
        <button class="btn" onclick="changeLogo()">Change Logo</button>
        <button class="btn" onclick="changeFont()">Change Font</button>
        <button class="btn" onclick="toggleAttr('show-header')">Toggle Header</button>
        <button class="btn" onclick="toggleAttr('show-info')">Toggle Info Section</button>
        <button class="btn" onclick="toggleAttr('allow-authentication')">Toggle Auth Section</button>
        <button class="btn" onclick="toggleAttr('allow-try')">Toggle Try mode</button>
        <button class="btn" onclick="toggleTheme()">Change Theme</button>
        <button class="btn" onclick="changeAttr('spec-url')">Change Spec URL</button>
        <button class="btn" onclick="toggleAttr('allow-search')">Toggle Search</button>
        <button class="btn" onclick="toggleAttr('allow-spec-url-load')">Toggle Spec URL Load</button>
        <button class="btn" onclick="toggleAttr('allow-spec-file-load')">Toggle Spec File Load</button>
      </div>
    </rapi-doc>
  </body>
</html>